package cn.tingting.context;

import com.alibaba.fastjson.JSON;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

public class UserContextHolder {
    public static UserContext context(){
        //获取登录用户信息
        SecurityContext context = SecurityContextHolder.getContext();
        //用户名
        String userInfoJson = context.getAuthentication().getPrincipal().toString();

        return JSON.parseObject(userInfoJson,UserContext.class);
    }
}
